package cn.nawang.ebeim.api.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.nawang.ebeim.api.service.AuthorizationCheckService;
import cn.nawang.ebeim.api.utils.Constant;

/**
 * @ClassName: AuthorizationCheckController
 * @Description: TODO
 * @author fanyb
 * @date Oct 26, 2015 8:21:35 PM
 * @version v1.0
 */
@RestController
public class AuthorizationCheckController {
  private static final Logger LOG = LoggerFactory.getLogger(AuthorizationCheckController.class);

  @Autowired
  private AuthorizationCheckService authorizationCheckService;

  @RequestMapping(value = "/token/authorization/check", method = RequestMethod.GET)
  public Map<String, Object> AuthCheck(String username, String code, String bindDevice,
      String bindDeviceName, String key) {
    LOG.info("/token/authorization/check {}", username, code, bindDevice, bindDeviceName);
    Map<String, Object> map = new HashMap<String, Object>();
    map = authorizationCheckService.authorizationCheck(map, username, code, bindDevice,
        bindDeviceName, key);
    LOG.debug("AuthCheck {}", map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 无授权验证
   * @param username
   * @return Map<String,Object>
   * @date Oct 27, 20153:06:41 PM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/no_authorization/check", method = RequestMethod.GET)
  public Map<String, Object> noAuthorizetionCheck(String username) {
    LOG.info("/token/no_authorization/check {}",username);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Constant.CODE_ERROR);
    authorizationCheckService.noAuthorizetionCheck(map, username);
    LOG.debug("noAuthorizetionCheck {}",map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: key无关联验证
   * @param username
   * @param code
   * @return Map<String,Object>
   * @date Oct 28, 20158:47:53 AM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/key_no_bind/check", method = RequestMethod.GET)
  public Map<String, Object> keyNoBindCheck(String username, String code, String key) {
    LOG.info("/token/key_no_bind/check {}", username, code, key);
    Map<String, Object> map = new HashMap<String, Object>();
    authorizationCheckService.keyNoBindCheck(map, username, code, key);
    LOG.debug("keyNoBindCheck {}",map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: key关联验证
   * @param username
   * @param code
   * @param bindDevice
   * @param bindDeviceName
   * @return Map<String,Object>
   * @date Oct 28, 20158:48:14 AM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/key_bind/check", method = RequestMethod.GET)
  public Map<String, Object> keyBindCheck(String username, String code, String bindDevice,
      String bindDeviceName, String key) {
    LOG.info("/token/key_bind/check {}", username, code, bindDevice, bindDeviceName, key);
    Map<String, Object> map = new HashMap<String, Object>();
    authorizationCheckService.keyBindCheck(map, username, code, bindDevice, bindDeviceName, key);
    LOG.debug("keyBindCheck {}",map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 授权码不关联
   * @param username
   * @param code
   * @return Map<String,Object>
   * @date Oct 28, 20158:49:26 AM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/authorization_code_no_bind/check", method = RequestMethod.GET)
  public Map<String, Object> authorizationCodeNoBindCheck(String username, String code) {
    LOG.info("/token/authorization_code_no_bind/check {}", username, code);
    Map<String, Object> map = new HashMap<String, Object>();
    authorizationCheckService.authorizationCodeNoBindCheck(map, username, code);
    LOG.debug("authorizationCodeNoBindCheck {}",map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 授权码绑定验证
   * @param username
   * @param code
   * @param bindDevice
   * @param bindDeviceName
   * @return Map<String,Object>
   * @date Oct 28, 20158:49:50 AM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/authorization_code_bind/check", method = RequestMethod.GET)
  public Map<String, Object> authorizationCodeBindCheck(String username, String code,
      String bindDevice, String bindDeviceName) {
    LOG.info("/token/authorization_code_bind/check {}", username, code, bindDevice, bindDeviceName);
    Map<String, Object> map = new HashMap<String, Object>();
    authorizationCheckService.authorizationCodeBindCheck(map, username, code, bindDevice,
        bindDeviceName);
    LOG.debug("authorizationCodeBindCheck {}",map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 授权有效期验证
   * @param username
   * @return Map<String,Object>
   * @date Oct 28, 20158:50:13 AM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/over_auth_time", method = RequestMethod.GET)
  public Map<String, Object> isOverAuthTime(String username) {
    LOG.info("/token/over_auth_time {}", username);
    Map<String, Object> map = new HashMap<String, Object>();
    authorizationCheckService.isOverAuthTime(map, username);
    LOG.debug("isOverAuthTime {}",map);
    return map;
  }

  /**
   * 
   * @author fanyb
   * @Description: 容量是否超过验证
   * @param username
   * @return Map<String,Object>
   * @date Oct 28, 20158:50:34 AM
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "/token/over_capacity", method = RequestMethod.GET)
  public Map<String, Object> isOverCapacity(String username) {
    LOG.info("/token/over_capacity {}", username);
    Map<String, Object> map = new HashMap<String, Object>();
    authorizationCheckService.isOverCapacity(map, username);
    LOG.debug("isOverCapacity {}",map);
    return map;
  }
}
